﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Цвет_и_оттенки
{
    public partial class Form1 : Form
    {
        const int vertSize = 5;

        public Form1()
        {
            InitializeComponent();

            imB.Image = new Bitmap(imB.Width, imB.Height);
            RebuildImB();
            ReBuild();
        }

        void RebuildImB()
        {
            int diap;
            if (!int.TryParse(txbStepSize.Text.Trim(), out diap)) return;

            Graphics gr = Graphics.FromImage(imB.Image);
            gr.Clear(Color.White);

            for (int i = 0; i < 360; i++)
            {
                gr.FillRectangle(new SolidBrush(new ClrHSV(i, 100, 100).ToRGB()), i * 2, 0, 2, imB.Height);
                gr.DrawRectangle(Pens.Black, ((int)trB.Value * 2) - diap, 0, diap * 2, imB.Height);
                //gr.DrawRectangle(Pens.Black, (int)trB.Value * 2, 0, 1, imB.Height);
            }

            gr.Dispose();
            imB.Refresh();
        }

        void ReBuild()
        {
            int sL = 3;
            int sR = 3;
            int step = 10;
            if (!int.TryParse(txbStepLeft.Text.Trim(), out sL)) return;
            if (!int.TryParse(txbStepRight.Text.Trim(), out sR)) return;
            if (!int.TryParse(txbStepSize.Text.Trim(), out step)) return;
            step /= sL + 1 + sR;
            BuildPallete(new ClrHSV((int)trB.Value, 100, 100), sL, sR, step, 30, 100);
        }

        void BuildPallete(ClrHSV baseColor, int stepsLeft, int stepsRight, int stepSize, int minB, int maxB)
        {
            if (im.Image != null) im.Image.Dispose();
            im.Image = new Bitmap(im.Width, im.Height);
            Graphics gr = Graphics.FromImage(im.Image);
            gr.Clear(Color.White);

            List<List<ClrHSV>> plt = GetPallete(baseColor, stepsLeft, stepsRight, stepSize, minB, maxB);

            float stepX = im.Width / (float)plt.Count;
            float stepY = im.Height / (float)plt[0].Count;

            Font fnt = new Font(Font, FontStyle.Bold);

            for (int i = 0; i < plt.Count; i++)
                for (int j = 0; j < plt[i].Count; j++)
                {
                    gr.FillRectangle(new SolidBrush(plt[i][j].ToRGB()), i * stepX+5, j * stepY+5, stepX-10, stepY-10);
                    //gr.DrawRectangle(Pens.Black, i * stepX, j * stepY, stepX, stepY);
                    gr.DrawString((j * plt.Count + i + 1).ToString(), fnt, Brushes.White, i * stepX+7, j * stepY+7);

                }

            gr.Dispose();
            im.Refresh();
        }

        List<List<ClrHSV>> GetPallete(ClrHSV baseColor, int stepsLeft, int stepsRight, int stepSize, int minB, int maxB)
        {
            ClrHSV baseClr = baseColor;

            int lenX = stepsLeft + 1 + stepsRight;
            List<List<ClrHSV>> ret = new List<List<ClrHSV>>();
            for (int i = 0; i < lenX; i++)
            {
                double h = baseClr.H + (i - stepsLeft) * stepSize;
                if (h < 0) h += 360;
                if (h >= 360) h -= 360;
                ret.Add(GetPallete7Line(new ClrHSV(h, baseClr.S, baseClr.B), minB, maxB));
            }
            return ret;
        }

        List<ClrHSV> GetPallete7Line(ClrHSV baseColor, int minB, int maxB)
        {
            double step = (maxB - minB) / ((double)vertSize - 2);
            List<ClrHSV> ret = new List<ClrHSV>();
            /*for (int i = 0; i < vertSize; i++)
            {
                //ret.Add(new ClrHSV(baseColor.H, baseColor.S, maxB - step * i));
               // ret.Add(new ClrHSV(baseColor.H, maxB - step * i, baseColor.B));
                if (i<3) ret.Add(new ClrHSV(baseColor.H, 100, maxB - step * i));
                else 
            }*/

            if (chbxB.Checked)
            {
                ret.Add(new ClrHSV(baseColor.H, 100, 100));
                ret.Add(new ClrHSV(baseColor.H, 100, 85));
                ret.Add(new ClrHSV(baseColor.H, 100, 60));
                ret.Add(new ClrHSV(baseColor.H, 100, 45));
                ret.Add(new ClrHSV(baseColor.H, 100, 30));
            }
            else
            {
                ret.Add(new ClrHSV(baseColor.H, 30, 100));
                ret.Add(new ClrHSV(baseColor.H, 65, 100));
                ret.Add(new ClrHSV(baseColor.H, 100, 100));
                ret.Add(new ClrHSV(baseColor.H, 100, 75));
                ret.Add(new ClrHSV(baseColor.H, 100, 50));
            }





            return ret;
        }

        #region *** HSV *******************************************

        public struct YMultyColor
        {
            public Color rgb;

            public ClrHSV hsv
            {
                get
                {
                    return RGB2HSV(rgb);
                }
                set
                {
                    rgb = HSV2RGB(value);
                }
            }

            ClrHSV RGB2HSV(Color clr)
            {
                /*H - цветовой тон (0-360ш), 0ш - красный
                S - насыщенность (0-1)
                V - светлота (0-1)*/
                double H = 0;
                double S;
                double Br;

                Br = MAX(clr);

                //Определение насыщенности

                double TEMP = MIN(clr);
                if (Br == 0) S = 0;
                else S = (Br - TEMP) / Br;

                //Определение цветового тона

                if (S == 0)
                {
                    // неопределенность
                    H = 360;
                }
                else
                {
                    double R = clr.R / 255.0;
                    double G = clr.G / 255.0;
                    double B = clr.B / 255.0;

                    double Cr = (Br - R) / (Br - TEMP);
                    double Cg = (Br - G) / (Br - TEMP);
                    double Cb = (Br - B) / (Br - TEMP);

                    //Цвет между желтым и пурпурным/

                    if (R == Br) H = Cb - Cg;

                    //Цвет между голубым и желтым/

                    if (G == Br) H = 2.0 + Cr - Cb;

                    //Цвет между пурпурным и голубым/

                    if (B == Br) H = 4.0 + Cg - Cr;

                    H = H * 60.0;

                    //Приведение к положительным величинам/

                    if (H < 0) H = H + 360.0;
                }

                return new ClrHSV(H, S * 100.0, Br * 100.0);
            }

            double MIN(Color clr)
            {
                double R = clr.R / 255.0;
                double G = clr.G / 255.0;
                double B = clr.B / 255.0;
                double ret = R;
                if (G < ret) ret = G;
                if (B < ret) ret = B;
                return ret;
            }

            double MAX(Color clr)
            {
                double R = clr.R / 255.0;
                double G = clr.G / 255.0;
                double B = clr.B / 255.0;
                double ret = R;
                if (G > ret) ret = G;
                if (B > ret) ret = B;
                return ret;
            }

            Color HSV2RGB(ClrHSV c)
            {
                double S = c.S / 100.0;
                double B = c.B / 100.0;

                if (c.H == 360 && S == 0 && B == 1)
                    return Color.White;

                while (c.H >= 360)
                    c.H -= 360;

                c.H /= 60.0;
                int ii = (int)(c.H);

                double fr = c.H - ii;

                byte c1 = (byte)((B * (1.0 - S)) * 255);
                byte c2 = (byte)((B * (1.0 - S * fr)) * 255);
                byte c3 = (byte)((B * (1.0 - S * (1.0 - fr))) * 255);

                byte val = (byte)(B * 255);
                byte r = 0, g = 0, b = 0;
                switch (ii)
                {
                    case 0: { r = val; g = c3; b = c1; break; }
                    case 1: { r = c2; g = val; b = c1; break; }
                    case 2: { r = c1; g = val; b = c3; break; }
                    case 3: { r = c1; g = c2; b = val; break; }
                    case 4: { r = c3; g = c1; b = val; break; }
                    case 5: { r = val; g = c1; b = c2; break; }
                }
                return Color.FromArgb(r, g, b);
            }

            public YMultyColor(Color clr)
            {
                rgb = clr;
            }
            public YMultyColor(ClrHSV c)
            {
                rgb = Color.Black;
                rgb = HSV2RGB(c);
            }

            /// <summary>
            /// Hue - оттенок (град)(0 - 359 (360 - отсутствие оттенка (серый))), Saturation - насыщенность % (0 - серый - 100 самый насыщеный), Brightness - яркость (светлость) % (0 - черный 100 - белый)
            /// </summary>
            public YMultyColor(double Hue, double Saturation, double Brightness)
            {
                rgb = Color.Black;
                rgb = HSV2RGB(new ClrHSV(Hue, Saturation, Brightness));
            }

        }

        public struct ClrHSV
        {
            public double H;
            public double S;
            public double B;

            /// <summary>
            /// Hue - оттенок, Saturation - насыщенность, Brightness - яркость
            /// </summary>
            public ClrHSV(double h, double s, double b)
            {
                H = h;
                S = s;
                B = b;
            }

            public ClrHSV(Color clr)
            {
                /*H - цветовой тон (0-360ш), 0ш - красный
                S - насыщенность (0-1)
                V - светлота (0-1)*/
                double H_ = 0;
                double S_;
                double Br_;

                Br_ = MAX(clr);

                //Определение насыщенности

                double TEMP = MIN(clr);
                if (Br_ == 0) S_ = 0;
                else S_ = (Br_ - TEMP) / Br_;

                //Определение цветового тона

                if (S_ == 0)
                {
                    // неопределенность
                    H_ = 360;
                }
                else
                {
                    double r = clr.R / 255.0;
                    double g = clr.G / 255.0;
                    double b = clr.B / 255.0;

                    double Cr = (Br_ - r) / (Br_ - TEMP);
                    double Cg = (Br_ - g) / (Br_ - TEMP);
                    double Cb = (Br_ - b) / (Br_ - TEMP);

                    //Цвет между желтым и пурпурным/

                    if (r == Br_) H_ = Cb - Cg;

                    //Цвет между голубым и желтым/

                    if (g == Br_) H_ = 2.0 + Cr - Cb;

                    //Цвет между пурпурным и голубым/

                    if (b == Br_) H_ = 4.0 + Cg - Cr;

                    H_ = H_ * 60.0;

                    //Приведение к положительным величинам/

                    if (H_ < 0) H_ = H_ + 360.0;
                }

                H = H_;
                S = S_ * 100.0;
                B = Br_ * 100.0;
            }

            static double MIN(Color clr)
            {
                double R = clr.R / 255.0;
                double G = clr.G / 255.0;
                double B = clr.B / 255.0;
                double ret = R;
                if (G < ret) ret = G;
                if (B < ret) ret = B;
                return ret;
            }

            static double MAX(Color clr)
            {
                double R = clr.R / 255.0;
                double G = clr.G / 255.0;
                double B = clr.B / 255.0;
                double ret = R;
                if (G > ret) ret = G;
                if (B > ret) ret = B;
                return ret;
            }

            public Color ToRGB()
            {
                double S_ = S / 100.0;
                double B_ = B / 100.0;

                if (H == 360 && S_ == 0 && B_ == 1)
                    return Color.White;

                while (H >= 360)
                    H -= 360;

                H /= 60.0;
                int ii = (int)(H);

                double fr = H - ii;

                byte c1 = (byte)((B_ * (1.0 - S_)) * 255);
                byte c2 = (byte)((B_ * (1.0 - S_ * fr)) * 255);
                byte c3 = (byte)((B_ * (1.0 - S_ * (1.0 - fr))) * 255);

                byte val = (byte)(B_ * 255);
                byte r = 0, g = 0, b = 0;
                switch (ii)
                {
                    case 0: { r = val; g = c3; b = c1; break; }
                    case 1: { r = c2; g = val; b = c1; break; }
                    case 2: { r = c1; g = val; b = c3; break; }
                    case 3: { r = c1; g = c2; b = val; break; }
                    case 4: { r = c3; g = c1; b = val; break; }
                    case 5: { r = val; g = c1; b = c2; break; }
                }
                return Color.FromArgb(r, g, b);
            }
        }

        #endregion *** HSV *******************************************

        #region *** цвета *****************************************************
        public class YStandartColor
        {
            /// <summary>
            /// Всего цветов 141. номер цвета определяются по алфавиту
            /// </summary>
            public static Color GetColorByNum(int num)
            {
                switch (num)
                {
                    case 0: return Color.AliceBlue;
                    case 1: return Color.AntiqueWhite;
                    case 2: return Color.Aqua;
                    case 3: return Color.Aquamarine;
                    case 4: return Color.Azure;
                    case 5: return Color.Beige;
                    case 6: return Color.Bisque;
                    case 7: return Color.Black;
                    case 8: return Color.BlanchedAlmond;
                    case 9: return Color.Blue;
                    case 10: return Color.BlueViolet;
                    case 11: return Color.Brown;
                    case 12: return Color.BurlyWood;
                    case 13: return Color.CadetBlue;
                    case 14: return Color.Chartreuse;
                    case 15: return Color.Chocolate;
                    case 16: return Color.Coral;
                    case 17: return Color.CornflowerBlue;
                    case 18: return Color.Cornsilk;
                    case 19: return Color.Crimson;
                    case 20: return Color.Cyan;
                    case 21: return Color.DarkBlue;
                    case 22: return Color.DarkCyan;
                    case 23: return Color.DarkGoldenrod;
                    case 24: return Color.DarkGray;
                    case 25: return Color.DarkGreen;
                    case 26: return Color.DarkKhaki;
                    case 27: return Color.DarkMagenta;
                    case 28: return Color.DarkOliveGreen;
                    case 29: return Color.DarkOrange;
                    case 30: return Color.DarkOrchid;
                    case 31: return Color.DarkRed;
                    case 32: return Color.DarkSalmon;
                    case 33: return Color.DarkSeaGreen;
                    case 34: return Color.DarkSlateBlue;
                    case 35: return Color.DarkSlateGray;
                    case 36: return Color.DarkTurquoise;
                    case 37: return Color.DarkViolet;
                    case 38: return Color.DeepPink;
                    case 39: return Color.DeepSkyBlue;
                    case 40: return Color.DimGray;
                    case 41: return Color.DodgerBlue;
                    case 42: return Color.Firebrick;
                    case 43: return Color.FloralWhite;
                    case 44: return Color.ForestGreen;
                    case 45: return Color.Fuchsia;
                    case 46: return Color.Gainsboro;
                    case 47: return Color.GhostWhite;
                    case 48: return Color.Gold;
                    case 49: return Color.Goldenrod;
                    case 50: return Color.Gray;
                    case 51: return Color.Green;
                    case 52: return Color.GreenYellow;
                    case 53: return Color.Honeydew;
                    case 54: return Color.HotPink;
                    case 55: return Color.IndianRed;
                    case 56: return Color.Indigo;
                    case 57: return Color.Ivory;
                    case 58: return Color.Khaki;
                    case 59: return Color.Lavender;
                    case 60: return Color.LavenderBlush;
                    case 61: return Color.LawnGreen;
                    case 62: return Color.LemonChiffon;
                    case 63: return Color.LightBlue;
                    case 64: return Color.LightCoral;
                    case 65: return Color.LightCyan;
                    case 66: return Color.LightGoldenrodYellow;
                    case 67: return Color.LightGray;
                    case 68: return Color.LightGreen;
                    case 69: return Color.LightPink;
                    case 70: return Color.LightSalmon;
                    case 71: return Color.LightSeaGreen;
                    case 72: return Color.LightSkyBlue;
                    case 73: return Color.LightSlateGray;
                    case 74: return Color.LightSteelBlue;
                    case 75: return Color.LightYellow;
                    case 76: return Color.Lime;
                    case 77: return Color.LimeGreen;
                    case 78: return Color.Linen;
                    case 79: return Color.Magenta;
                    case 80: return Color.Maroon;
                    case 81: return Color.MediumAquamarine;
                    case 82: return Color.MediumBlue;
                    case 83: return Color.MediumOrchid;
                    case 84: return Color.MediumPurple;
                    case 85: return Color.MediumSeaGreen;
                    case 86: return Color.MediumSlateBlue;
                    case 87: return Color.MediumSpringGreen;
                    case 88: return Color.MediumTurquoise;
                    case 89: return Color.MediumVioletRed;
                    case 90: return Color.MidnightBlue;
                    case 91: return Color.MintCream;
                    case 92: return Color.MistyRose;
                    case 93: return Color.Moccasin;
                    case 94: return Color.NavajoWhite;
                    case 95: return Color.Navy;
                    case 96: return Color.OldLace;
                    case 97: return Color.Olive;
                    case 98: return Color.OliveDrab;
                    case 99: return Color.Orange;
                    case 100: return Color.OrangeRed;
                    case 101: return Color.Orchid;
                    case 102: return Color.PaleGoldenrod;
                    case 103: return Color.PaleGreen;
                    case 104: return Color.PaleTurquoise;
                    case 105: return Color.PaleVioletRed;
                    case 106: return Color.PapayaWhip;
                    case 107: return Color.PeachPuff;
                    case 108: return Color.Peru;
                    case 109: return Color.Pink;
                    case 110: return Color.Plum;
                    case 111: return Color.PowderBlue;
                    case 112: return Color.Purple;
                    case 113: return Color.Red;
                    case 114: return Color.RosyBrown;
                    case 115: return Color.RoyalBlue;
                    case 116: return Color.SaddleBrown;
                    case 117: return Color.Salmon;
                    case 118: return Color.SandyBrown;
                    case 119: return Color.SeaGreen;
                    case 120: return Color.SeaShell;
                    case 121: return Color.Sienna;
                    case 122: return Color.Silver;
                    case 123: return Color.SkyBlue;
                    case 124: return Color.SlateBlue;
                    case 125: return Color.SlateGray;
                    case 126: return Color.Snow;
                    case 127: return Color.SpringGreen;
                    case 128: return Color.SteelBlue;
                    case 129: return Color.Tan;
                    case 130: return Color.Teal;
                    case 131: return Color.Thistle;
                    case 132: return Color.Tomato;
                    case 133: return Color.Transparent;
                    case 134: return Color.Turquoise;
                    case 135: return Color.Violet;
                    case 136: return Color.Wheat;
                    case 137: return Color.White;
                    case 138: return Color.WhiteSmoke;
                    case 139: return Color.Yellow;
                    case 140: return Color.YellowGreen;
                }
                return Color.Transparent;
            }

            /// <summary>
            /// Всего цветов 141. номер цвета определяются по радуге
            /// </summary>
            public static Color GetColorByNumH(int num)
            {
                switch (num)
                {
                    case 0: return Color.AliceBlue;
                    case 1: return Color.AntiqueWhite;
                    case 2: return Color.Aqua;
                    case 3: return Color.Aquamarine;
                    case 4: return Color.Azure;
                    case 5: return Color.Beige;
                    case 6: return Color.Bisque;
                    case 7: return Color.Black;
                    case 8: return Color.BlanchedAlmond;
                    case 9: return Color.Blue;
                    case 10: return Color.BlueViolet;
                    case 11: return Color.Brown;
                    case 12: return Color.BurlyWood;
                    case 13: return Color.CadetBlue;
                    case 14: return Color.Chartreuse;
                    case 15: return Color.Chocolate;
                    case 16: return Color.Coral;
                    case 17: return Color.CornflowerBlue;
                    case 18: return Color.Cornsilk;
                    case 19: return Color.Crimson;
                    case 20: return Color.Cyan;
                    case 21: return Color.DarkBlue;
                    case 22: return Color.DarkCyan;
                    case 23: return Color.DarkGoldenrod;
                    case 24: return Color.DarkGray;
                    case 25: return Color.DarkGreen;
                    case 26: return Color.DarkKhaki;
                    case 27: return Color.DarkMagenta;
                    case 28: return Color.DarkOliveGreen;
                    case 29: return Color.DarkOrange;
                    case 30: return Color.DarkOrchid;
                    case 31: return Color.DarkRed;
                    case 32: return Color.DarkSalmon;
                    case 33: return Color.DarkSeaGreen;
                    case 34: return Color.DarkSlateBlue;
                    case 35: return Color.DarkSlateGray;
                    case 36: return Color.DarkTurquoise;
                    case 37: return Color.DarkViolet;
                    case 38: return Color.DeepPink;
                    case 39: return Color.DeepSkyBlue;
                    case 40: return Color.DimGray;
                    case 41: return Color.DodgerBlue;
                    case 42: return Color.Firebrick;
                    case 43: return Color.FloralWhite;
                    case 44: return Color.ForestGreen;
                    case 45: return Color.Fuchsia;
                    case 46: return Color.Gainsboro;
                    case 47: return Color.GhostWhite;
                    case 48: return Color.Gold;
                    case 49: return Color.Goldenrod;
                    case 50: return Color.Gray;
                    case 51: return Color.Green;
                    case 52: return Color.GreenYellow;
                    case 53: return Color.Honeydew;
                    case 54: return Color.HotPink;
                    case 55: return Color.IndianRed;
                    case 56: return Color.Indigo;
                    case 57: return Color.Ivory;
                    case 58: return Color.Khaki;
                    case 59: return Color.Lavender;
                    case 60: return Color.LavenderBlush;
                    case 61: return Color.LawnGreen;
                    case 62: return Color.LemonChiffon;
                    case 63: return Color.LightBlue;
                    case 64: return Color.LightCoral;
                    case 65: return Color.LightCyan;
                    case 66: return Color.LightGoldenrodYellow;
                    case 67: return Color.LightGray;
                    case 68: return Color.LightGreen;
                    case 69: return Color.LightPink;
                    case 70: return Color.LightSalmon;
                    case 71: return Color.LightSeaGreen;
                    case 72: return Color.LightSkyBlue;
                    case 73: return Color.LightSlateGray;
                    case 74: return Color.LightSteelBlue;
                    case 75: return Color.LightYellow;
                    case 76: return Color.Lime;
                    case 77: return Color.LimeGreen;
                    case 78: return Color.Linen;
                    case 79: return Color.Magenta;
                    case 80: return Color.Maroon;
                    case 81: return Color.MediumAquamarine;
                    case 82: return Color.MediumBlue;
                    case 83: return Color.MediumOrchid;
                    case 84: return Color.MediumPurple;
                    case 85: return Color.MediumSeaGreen;
                    case 86: return Color.MediumSlateBlue;
                    case 87: return Color.MediumSpringGreen;
                    case 88: return Color.MediumTurquoise;
                    case 89: return Color.MediumVioletRed;
                    case 90: return Color.MidnightBlue;
                    case 91: return Color.MintCream;
                    case 92: return Color.MistyRose;
                    case 93: return Color.Moccasin;
                    case 94: return Color.NavajoWhite;
                    case 95: return Color.Navy;
                    case 96: return Color.OldLace;
                    case 97: return Color.Olive;
                    case 98: return Color.OliveDrab;
                    case 99: return Color.Orange;
                    case 100: return Color.OrangeRed;
                    case 101: return Color.Orchid;
                    case 102: return Color.PaleGoldenrod;
                    case 103: return Color.PaleGreen;
                    case 104: return Color.PaleTurquoise;
                    case 105: return Color.PaleVioletRed;
                    case 106: return Color.PapayaWhip;
                    case 107: return Color.PeachPuff;
                    case 108: return Color.Peru;
                    case 109: return Color.Pink;
                    case 110: return Color.Plum;
                    case 111: return Color.PowderBlue;
                    case 112: return Color.Purple;
                    case 113: return Color.Red;
                    case 114: return Color.RosyBrown;
                    case 115: return Color.RoyalBlue;
                    case 116: return Color.SaddleBrown;
                    case 117: return Color.Salmon;
                    case 118: return Color.SandyBrown;
                    case 119: return Color.SeaGreen;
                    case 120: return Color.SeaShell;
                    case 121: return Color.Sienna;
                    case 122: return Color.Silver;
                    case 123: return Color.SkyBlue;
                    case 124: return Color.SlateBlue;
                    case 125: return Color.SlateGray;
                    case 126: return Color.Snow;
                    case 127: return Color.SpringGreen;
                    case 128: return Color.SteelBlue;
                    case 129: return Color.Tan;
                    case 130: return Color.Teal;
                    case 131: return Color.Thistle;
                    case 132: return Color.Tomato;
                    case 133: return Color.Transparent;
                    case 134: return Color.Turquoise;
                    case 135: return Color.Violet;
                    case 136: return Color.Wheat;
                    case 137: return Color.White;
                    case 138: return Color.WhiteSmoke;
                    case 139: return Color.Yellow;
                    case 140: return Color.YellowGreen;
                }
                return Color.Transparent;
            }

            /// <summary>
            /// Определить стандартное имя цвета. Если для цвета нет стандартного имени, вернется ""
            /// </summary>
            public static String GetStandartColorName(Color clr, bool CheckAlpha)
            {
                for (int i = 0; i < 141; i++)
                {
                    Color clr1 = GetColorByNum(i);
                    if (i == 113)
                        clr1 = GetColorByNum(i);
                    if (((CheckAlpha && clr.A == clr1.A) || !CheckAlpha) && clr.R == clr1.R && clr.G == clr1.G && clr.B == clr1.B)
                        return clr1.ToString().Replace("Color ", "").Replace("[", "").Replace("]", "");
                }
                return "";

            }
        }
        #endregion *** цвета *****************************************************

        private void txb_TextChanged(object sender, EventArgs e)
        {
            ReBuild();
            if (sender == txbStepSize) RebuildImB();
        }

        private void trB_Scroll(object sender, EventArgs e)
        {
            pnlColor.BackColor = new ClrHSV((int)trB.Value, 100, 100).ToRGB();
            ReBuild();
            RebuildImB();
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            ReBuild();
        }

        private void Form1_ResizeEnd(object sender, EventArgs e)
        {
            ReBuild();
        }


    }
}
